package com.tgy.algorithm.base._bfprt算法;

public class _bfprt {

    public static int bfprt(int[] nums, int k) {


        return doBfprt(nums,0,nums.length - 1,k);
    }

    public static int doBfprt(int[] nums, int left, int right, int k) {

        if (left >= right) {
            return nums[left];
        }

        findMiddleOfMiddle(nums,left,right);
        return 0;
    }

    public static int findMiddleOfMiddle(int[] nums,int start,int end) {

        int step = 5;
        int len = end - start + 1;
//        13
//        10 11 12
        int moddleLen = len / step;
        if (moddleLen * step < len) {
            moddleLen++;
        }

        int[] middles = new int[moddleLen];
        // 0 4 4/2
        // 10 11 1 / 2 10 11 12 2/2
        for (int i = 0; i < moddleLen; i++) {
            int left = start + i * step;
            int right = start + (i+1) * step;
            if (right > len) {
                right = len;
            }
            sort(nums,left, right - 1);
            middles[i] = nums[left+(right- left) >> 1];
        }

        return doBfprt(middles,0,moddleLen-1,moddleLen>>1);
    }

    public static void sort(int[] nums,int left,int right) {

    }

    public static void main(String[] args) {

    }
}
